
<?php
	
	include '../lib/config.inc.php';
	$codig = $_GET['codig'];
	$sql = mysql_query("SELECT membros.id, membros.membro, membros.sexo, membros.m_status, membros.estado_civil, membros.data_nasc, membros.cpf, igrejas.igreja FROM membros, igrejas WHERE membros.igreja_id = igrejas.id AND igrejas.id = $codig ORDER BY igrejas.igreja ASC");
	$igrej = mysql_fetch_array(mysql_query("SELECT igreja FROM igrejas WHERE igrejas.id = $codig"));
	require("../fpdf/fpdf.php");
	
	$pdf= new FPDF("P","pt","A4");
	
	$pdf->AddPage();
	$pdf->SetFont('Arial','B',14);
	$pdf->Cell(0,20,utf8_decode("Relatório de Membros da igreja {$igrej['igreja']}"),0,1,'C');
	$pdf->Cell(520,5,"","B",1,'C');
	$pdf->Ln(20);
	
	$n = 0;
	$pdf->SetFont('Arial','',10);
	$pdf->Cell(15,20,utf8_decode('id'),1,0,"L");
	$pdf->Cell(140,20,utf8_decode('Membro'),1,0,"L");
	$pdf->Cell(80,20,utf8_decode('CPF'),1,0,"L");
	//$pdf->Cell(55,20,utf8_decode('Sexo'),1,0,"L");
	$pdf->Cell(80,20,utf8_decode('Est. Civil'),1,0,"L");
	$pdf->Cell(60,20,utf8_decode('Nasc.'),1,0,"L");
	$pdf->Cell(120,20,utf8_decode('Igreja'),1,0,"L");
	$pdf->Cell(40,20,utf8_decode('Status'),1,0,"L");
	$pdf->Ln();
	while ($l = mysql_fetch_array($sql)){
		$pdf->Cell(15,20,utf8_decode($l['id']),1,0,"L");
		$pdf->Cell(140,20,utf8_decode($l['membro']),1,0,"L");
		$pdf->Cell(80,20,utf8_decode($l['cpf']),1,0,"L");
		//$pdf->Cell(55,20,utf8_decode($l['sexo']),1,0,"L");
		$pdf->Cell(80,20,utf8_decode($l['estado_civil']),1,0,"L");
		$pdf->Cell(60,20,date('d/m/Y', strtotime($l['data_nasc'])),1,0,"L");
		$pdf->Cell(120,20,utf8_decode($l['igreja']),1,0,"L");
		if($l['m_status'] == 1){
			$pdf->Cell(40,20,utf8_decode('Ativo'),1,0,"L");
		}
		if($l['m_status'] == 0){
			$pdf->Cell(40,20,utf8_decode('Inativo'),1,0,"L");
		}
		$pdf->Ln();
		$n++;
	}
	$pdf->Ln(10);
	//$n = mysql_num_rows($sql);
	$pdf->Cell(150, 20, utf8_decode("Total de Membros: ".$n));
	$pdf->Ln(40);
	
	$pdf->Output();
	
?>